{{include_file name='public/header' title='搜索项目'}}

</head>

<body>

<div id="wrapper">

    <!-- Navigation -->
    {{include_file name='public/nav' sidebar='user_sidebar'}}
    <div id="page-wrapper">

        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">搜索项目</h1>
                <div class="search">
                    <div class="well">

                        <form class="form-inline" action="{{url()}}" method="get">
                            <div class="form-group">
                                <label>项目名</label>
                                <input name="search[project]" type="text" class="form-control" placeholder="支持模糊查询" value="{{$search.project}}">
                            </div>

                            <div class="form-group">
                                <label>创建人</label>
                                <input name="search[user]" type="text" class="form-control" placeholder="支持模糊查询" value="{{$search.user}}">
                            </div>

                            <button type="submit" class="btn btn-primary">搜索</button>
                        </form>

                    </div>
                </div>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">

                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>项目名称</th>
                                    <th>项目简介</th>
                                    <th>创建人/账号</th>
                                    <th>成员数</th>
                                    <th>创建时间</th>

                                    <th>操作面板</th>
                                </tr>
                                </thead>
                                <tbody>
                                {{if $projects}}
                                {{foreach $projects as $project}}
                                {{$project_id = $project.id}}
                                {{$user_id = $project.user_id}}
                                <tr>
                                    <td >{{$project.title|truncate:10}}</td>
                                    <td >{{$project.intro|truncate:30}}</td>
                                    <td >{{_uri('user', $user_id, 'name')}}<br>{{_uri('user', $user_id, 'email')}}</td>
                                    <td >{{\app\project::get_member_num($project_id)}}</td>
                                    <td >{{$project.add_time}}</td>
                                    <td >

                                        {{if \app\user::is_creater($project_id)}}
                                        <a class="btn btn-info btn-xs disabled">创建者</a>
                                        {{else if \app\user::is_joiner($project_id)}}
                                        <a class="btn btn-warning btn-xs disabled">参与者</a>
                                        {{else if \app\user::is_appling($project_id)}}
                                        <a class="btn btn-warning btn-xs disabled">审核中</a>
                                        {{else}}
                                        <a class="btn btn-success btn-xs js_addProjectBtn" data-project_id="{{$project.id}}">加入项目</a>
                                        {{/if}}

                                    </td>
                                </tr>
                                {{/foreach}}
                                {{/if}}

                                </tbody>
                            </table>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <div class="col-sm-12">
                {{include_file name='public/page'}}
            </div>

            <!-- /.col-lg-6 -->
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->
    <hr>
    <p class="text-center">{{get_config('copyright')}}</p>

    <script>
        $(function () {
            $(".js_addProjectBtn").click(function () {
                var thisObi = $(this);
                var url = "{{url('apply')}}";
                var projectId = thisObi.data('project_id');

                $.post(url, { project_id:projectId }, function(json){
                    if(json.code == 200 || json.code == 304){

                        thisObi.attr("disabled", "disabled").text('审核中');

                    }else{

                        thisObi.text('重新提交').removeAttr("disabled");
                    }

                    alert(json.msg, 2000);

                }, 'json');
            });
        });
    </script>

    {{include_file name='public/footer'}}
